//
//  DashedLineView.swift
//  kano
//
//  Created by Frank on 2024/9/19.
//

import UIKit

class DashedLineView: UIView {

    override func draw(_ rect: CGRect) {
        // 创建路径
        let path = UIBezierPath()
        path.move(to: CGPoint(x: 0, y: 0.5)) // 起点
        path.addLine(to: CGPoint(x: width, y: 0.5)) // 终点
        
        // 创建形状层
        let shapeLayer = CAShapeLayer()
        shapeLayer.path = path.cgPath
        
        // 设置虚线属性
        shapeLayer.strokeColor = UIColor.colorCBCACE.cgColor // 线条颜色
        shapeLayer.lineWidth = 2.0 // 线条宽度
        shapeLayer.lineDashPattern = [4, 2] // 虚线样式，4pt 画线，2pt 空白
        
        // 添加到视图
        layer.addSublayer(shapeLayer)
    }

}
